package com.fh.service.airsys.airlineemployee;

import java.text.DecimalFormat;
import java.util.List;

import javax.annotation.Resource;

import com.fh.Enum.EnFinalValue;
import com.fh.service.airsys.employeeaccinfo.EmployeeAccinfoService;
import com.fh.service.airsys.syscreditaccount.SysCreditAccountService;
import com.fh.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fh.dao.DaoSupport;
import com.fh.entity.Page;
import com.fh.util.PageData;


@Service("airlineemployeeService")
public class AirlineEmployeeService {

	@Resource(name = "daoSupport")
	private DaoSupport dao;
	@Autowired
	private SysCreditAccountService sysCreditAccountService;
	@Autowired
	private EmployeeAccinfoService employeeAccinfoService;
	
	/*
	* 新增
	*/
	public void save(PageData pd)throws Exception{
		Integer balance = Integer.valueOf(pd.getString("SA_CREDITLINE"));
		pd.put("SA_CREDITLINE",balance*100);
		dao.save("AirlineEmployeeMapper.save", pd);
		sysCreditAccountService.save(pd);
		employeeAccinfoService.save(pd);
	}
	
	/*
	* 删除
	*/
	public void delete(PageData pd)throws Exception{
		dao.delete("AirlineEmployeeMapper.delete", pd);
	}
	
	/*
	* 修改
	*/
	public void edit(PageData pd)throws Exception{
		dao.update("AirlineEmployeeMapper.edit", pd);
	}
	
	/*
	*列表
	*/
	public List<PageData> list(Page page)throws Exception{
		List<PageData> list = (List<PageData>) dao.findForList("AirlineEmployeeMapper.datalistPage", page);
		for (PageData pageData:list){
			DecimalFormat format = new DecimalFormat("######0.00");
			Double banlance = Double.valueOf((Integer)pageData.get("SA_BALANCE"));
			Double creditline = Double.valueOf((Integer)pageData.get("SA_CREDITLINE"));
			pageData.put("SA_BALANCE",format.format(banlance/100));
			pageData.put("SA_CREDITLINE",format.format(creditline/100));
			pageData.put("EI_SEX_VALUE", EnFinalValue.getName("SEX", (Integer) pageData.get("EI_SEX")));
			pageData.put("EI_IDTYPE_VALUE", EnFinalValue.getName("paperType", (Integer) pageData.get("EI_IDTYPE")));
			pageData.put("EI_STATE_VALUE", EnFinalValue.getName("workState", (Integer) pageData.get("EI_STATE")));
		}
		return list;
	}
	
	/*
	*列表(全部)
	*/
	public List<PageData> listAll(PageData pd)throws Exception{
		List<PageData> list = (List<PageData>)dao.findForList("AirlineEmployeeMapper.listAll", pd);
		return list;
	}
	
	/*
	* 通过id获取数据
	*/
	public PageData findById(PageData pd)throws Exception{
		return (PageData)dao.findForObject("AirlineEmployeeMapper.findById", pd);
	}
	
	/*
	* 批量删除
	*/
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		dao.delete("AirlineEmployeeMapper.deleteAll", ArrayDATA_IDS);
	}

	/**
	 * 根据员工id查询员工数据量
	 * @param pd
	 * @return
	 * @throws Exception
	 */
	public Long countFindById(PageData pd) throws Exception{
		PageData pageData = (PageData) dao.findForObject("AirlineEmployeeMapper.countFindById",pd);
		return (Long) pageData.get("num");
	}
	
}

